namespace Warehouse

open System.Collections.ObjectModel
open FSharp.Windows

[<AbstractClass>]
[<AllowNullLiteral>]
type BrandDetailsModel() = 
    inherit EntityModel<DataModel.Brand>()

    abstract Name : string with get, set
    abstract ClientDefaultRegularPct : decimal with get, set
    abstract ClientDefaultLitrSizePct : decimal with get, set
    abstract VendorDefaultRegularPct : decimal with get, set
    abstract VendorDefaultLitrSizePct : decimal with get, set

    override this.Init() = 
        this.Name <- this.Entity.Name
        this.ClientDefaultRegularPct <- this.Entity.ClientDefaultRegularProductCommission
        this.ClientDefaultLitrSizePct <- this.Entity.ClientDefaultLitrSizeProductCommission
        this.VendorDefaultRegularPct <- this.Entity.VendorDefaultRegularProductCommission
        this.VendorDefaultLitrSizePct <- this.Entity.VendorDefaultLitrSizeProductCommission

    override this.Flush() = 
        this.Entity.Name <- this.Name
        this.Entity.ClientDefaultRegularProductCommission <- this.ClientDefaultRegularPct
        this.Entity.ClientDefaultLitrSizeProductCommission <- this.ClientDefaultLitrSizePct
        this.Entity.VendorDefaultRegularProductCommission <- this.VendorDefaultRegularPct
        this.Entity.VendorDefaultLitrSizeProductCommission <- this.VendorDefaultLitrSizePct

    member this.IsChanged = 
        if this.IsNewEntity then true
        else 
            this.Name <> this.Entity.Name
            || this.ClientDefaultRegularPct <> this.Entity.ClientDefaultRegularProductCommission
            || this.ClientDefaultLitrSizePct <> this.Entity.ClientDefaultLitrSizeProductCommission
            || this.VendorDefaultRegularPct <> this.Entity.VendorDefaultRegularProductCommission
            || this.VendorDefaultLitrSizePct <> this.Entity.VendorDefaultLitrSizeProductCommission
            

[<AbstractClass>]
type BrandModel() = 
    inherit Model()

    abstract Items : BrandDetailsModel CollectionView with get, set
    abstract SelectedBrand : BrandDetailsModel with get, set

    [<NotifyDependencyChanged>]
    member this.IsSaveEnable = this.SelectedBrand <> null && this.SelectedBrand.IsChanged

    [<NotifyDependencyChanged>]
    member this.IsDeleteEnable = this.SelectedBrand <> null && not this.SelectedBrand.IsNewEntity
